/**
 * 
 */
package com.huawei.struts.service.imp;

import java.util.List;

import com.huawei.struts.dao.LjwUserTDAO;
import com.huawei.struts.exception.SystemException;
import com.huawei.struts.service.IUserService;
import com.huawei.struts.util.PageBean;
import com.st.model.LjwUserT;
import com.st.model.UserT;

/**
 * @author huganpu
 *
 */
public class UserService implements IUserService  {

	private LjwUserTDAO lwjUserDao;
	
	
	public void setLwjUserDao(LjwUserTDAO lwjUserDao) {
		this.lwjUserDao = lwjUserDao;
	}

	/**
	 * 添加用户
	 */
	public void addUser(LjwUserT user) throws SystemException {
		try {
			lwjUserDao.save(user);
		} catch (Exception e) {
			throw new SystemException("error.info", e.getCause());
		}
	}
	
	/**
	 * 删除用户
	 */
	public void delUser(LjwUserT user) throws SystemException {
		try{
			lwjUserDao.delete(user);
		} catch (Exception e) {
			throw new SystemException("error.info", e.getCause());
		}
	}

	/**
	 * 通过Id得到用户的详细信息
	 */
	public LjwUserT getUserInfoByid(Integer id) throws SystemException {
		return lwjUserDao.findById(id);
	}

	/**
	 * 得到用户详细列表
	 */
	public PageBean getUserList(LjwUserT user, PageBean pageBean) {
		int allRows=lwjUserDao.getAllRowCount(user);//得到记录总数
		PageBean page=pageBean.pagationTemplate(allRows, pageBean.getCurrentPage());//获取分页的全部信息
		List list=lwjUserDao.queryForPage(user, page);//得到结果集
		page.setList(list);
		return page;
	}
	
	/**
	 * 修改用户
	 */
	public void modifyUser(LjwUserT user) throws SystemException {
		try{
			lwjUserDao.merge(user);
		} catch (Exception e) {
			throw new SystemException("error.info", e.getCause());
		}
	}
	
	
	/**
	 * 登陆
	 */
	public boolean login(LjwUserT user) throws SystemException {
		return lwjUserDao.login(user);
	}

	 
	
	public LjwUserT getUserByName(String name) throws SystemException {
		LjwUserT user = new LjwUserT();
		List list = lwjUserDao.findByUserName(name);
		if (list != null && list.size() > 0) {
			user = (LjwUserT) list.get(0);
		}
		return user;
	}

	public int checkPermission(int role, String module, String opertor) {
		return lwjUserDao.checkPermission(role, module, opertor);
	}
	
	
	

}
